package com.zxl.tsc.login.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zxl.tsc.login.bean.User;
import com.zxl.tsc.login.dao.UserDao;
import com.zxl.tsc.login.service.LoginService;
import com.zxl.tsc.login.service.UserService;
import com.zxl.tsc.util.Encodes;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userDao;
	

	@Override
	public void regUser(User user) {
		String enPassword =  Encodes.entryptPassword(user.getPassword());
		user.setPassword(enPassword);
		this.userDao.regUser(user);
	}


	@Override
	public boolean checkUser(String userName) {
		User user = this.userDao.checkUser(userName);
		if (user == null) {
			return true;
		}else {
			return false;
		}
	}


	/* (non-Javadoc)
	 * @see com.zxl.tsc.login.service.UserService#getOneUser(java.lang.String)
	 * 根据用户名获取用户信息
	 */
	@Override
	public User getOneUser(String userName) {
		return this.userDao.checkUser(userName);
	}


	/* (non-Javadoc)
	 * @see com.zxl.tsc.login.service.UserService#updatePwd(java.lang.String, int)
	 * 更新密码
	 */
	@Override
	public void updatePwd(String newPwd, int userId) {
		this.userDao.updatePwd(Encodes.entryptPassword(newPwd),userId);
	}

}
